#include"Structt.h"
#include"Menu.h"
#include"function.h"

void input1(Student* s)
{
	printf("\n\tsno:");
	scanf("%d",s->sno );//
	
	printf("\n\tname:");
	puts(s->name);//
	
	printf("\n\tage:");
	scanf("%d",s->age);	
	
	printf("\n\tgender:");
	puts(s->gender);//
	
	int i = 0;
	while(1)
	{
		system("pause");
		system("cls");
		printf("\t1.录入病例\n");
		printf("\t0.结束录入\n");
		printf("\t(0-1)\n");
		int option ;
		scanf("%d",&option);
		switch(option){
			case 0:
				break;
			
			case 1:
				if (i>=5){
					printf("录入过多，请及时清理！");
					break;
				}
				input2(& (s->cc)[i]);
				break;
		}
	}
    
	return ;
}

void input2 (Cas* s)
{
	printf("\n\tdepart:");	
	puts(s->depart);
	
	printf("\n\tchest_size:");
	scanf("%lf",s->chest_size);
	
	printf("\n\ttall:");
	scanf("%lf",s->tall);
	
	printf("\n\tweight:");
	scanf("%lf",s->weight);
	
	printf("\n\tdiagnose:");
    puts(s->diagnose);
    
    printf("\n\tyear:");
    scanf("%d",s->year );
    
    printf("\n\tmonth:");
    scanf("\t%d",s->month );
    
	printf("\n\tday:");
    scanf("\t%d",s->day );
}

void statistic(Student* s,int n)//un
{
	//average about tall, weight and chest_size in the same age
	//average about tall, weight and chest_size in the same gender with the same age
}

void analyse(Student* s,int n)//un
{
	//rate of tall, weight and chest_size by days and years
}

Student* readfile(Student* s,int n)
{
	FILE* fp;
	fopen_s(&fp,"zxc_File","rb");
	if(!fp)exit(0);
	fread(s,sizeof(Student ),n,fp);
	fclose(fp);
	return s;
}

void savefile(Student* s,int n)
{
	FILE* fp;
	fopen_s(&fp,"zxc_File","wb");
	if(!fp)exit(0);
	fwrite(s,sizeof(Student ),n,fp);
	fclose(fp);
	return ;
}

void find_by_sno(Student* s,int n,int sno)
{
	for(int i = 0;i < n;i++){
		if( s[i].sno == sno )show1(&s[i]);
	}
}

void find_by_gender(Student* s,int n,char* gender)
{
	for(int i = 0;i < n;i++){
		if( strcmp(s[i].gender ,gender ) == 0 )show(&s[i]);
	}
}

void find_by_depart(Student* s,int n,char* depart)
{
	for(int i = 0;i < n;i++){
		if( strcmp(s[i].depart ,depart ) == 0 )show(&s[i]);
	}
}

void find_by_age(Student* s,int n,int age)
{
	for(int i = 0;i < n;i++){
	if( s[i].age == age )show(&s[i]);
	}
}

void find_by_name(Student* s,int n,char* name)
{
	for(int i = 0;i < n;i++){
		if( strcmp(s[i].name ,name ) == 0 )show(&s[i]);
	}
}

void traversal(Student* s,int n)//所有学生
{
	for(int i = 0; i < n; i++){
		if( s[i].sno == 0)break;
	     show(&s[i]);
	}
}

void show2(Cas* s)//一份记录
{

	printf("\tdepart:")
	puts(s->depart );
	
	printf("\tage:%d\n",s->age );
	
	printf("\ttall:%f\n",s->tall );
	
	printf("\tweight:%f\n",s->weight );
	
	printf("\tchest_size:%f\n",s->chest_size );
	
	printf("\tdiagnose:");
	puts(s->diagnose );
	
	printf("\tdate:%d.%d.%d",s->year ,s->month ,s->day );
	
	return ;
}

void show1(Student* s)//一个学生
{
	for(int i=0;i<5;i++){
		if(s->cc[i].age == 0 )return ;
		show2( &((s->cc)[i]) );
	}
	return ;
}
void deletE(Student* s)
{
	for(int i=0;i<5;i++){
		s->cc[i].age = 0 
	}
	return ;
}